package com.example.core.shiroLogin;

import org.apache.shiro.codec.Base64;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * @ClassName EncryptionUtil
 * @Author zhangzhaoyang
 * @Date 2019/10/21 9:59
 * shiro加密
 **/
public class EncryptionUtil {
    //加密解密次数
    private static int number = 6;

    /**
     * 封装好的shiro加密
     * */
    public static String encode(String souce){
        for(int i = 0 ; i < number ;i++){
            souce = encBase64(souce);
        }
        return souce;
    }

    /**
     * 封装好的shiro解密
     * */
    public static String decode(String souce){
        for(int i = 0 ; i < number ;i++){
            souce = decBase64(souce);
        }
        return souce;
    }




    /**
     * shiro Base64加密
     * */
    public static String encBase64(String souce){
        return Base64.encodeToString(souce.getBytes());
    }

    /**
     * shiro Base64解密
     * */
    public static String decBase64(String souce){
        return Base64.decodeToString(souce);
    }
    /**
     * souce需要加密的字符串
     * salt自定义盐
     * */
    public static String md5(String souce,String salt){
        return new Md5Hash(souce,salt).toString();
    }
}
